package com.googlecode.pwlodars.piteststat.tests.files;

import java.io.File;
import java.util.Arrays;
import java.util.List;

import org.hamcrest.Description;

import com.googlecode.pwlodars.piteststat.tests.SmartBaseMatcher;

public class ContainsFilesWithNames extends SmartBaseMatcher<List<File>>{

	private String[] expectedNames;
	private String unexpectedName;
	
	public ContainsFilesWithNames(String[] names) {
		this.expectedNames=names;
	}

	public void describeTo(Description description) {
		description.appendText("expected : "+Arrays.toString(expectedNames)+" but received file with name : "+unexpectedName);
	}

	@Override
	public boolean performConditionChecking(List<File> files) throws Exception {
		for (int currentFileIndex = 0; currentFileIndex < files.size(); currentFileIndex++) {
			String currentFileName = files.get(currentFileIndex).getName();
			if(!currentFileName.equals(expectedNames[currentFileIndex].trim())){
				unexpectedName=currentFileName;
				return false;
			}
		}
		
		return true;
	}
	
	
	public static ContainsFilesWithNames containsFilesWithNames(String... names){
		return new ContainsFilesWithNames(names);
	}

}
